const router=require('koa-router')();
const requset=require('request');

//获取SDKtoken
router.get('/GetToken',async (ctx)=>{
    let bodys={
        "grant_type":"client_credentials",
        "client_id":"YXA65tME8O2REeiiYHHWJYmwfQ",
        "client_secret":"YXA6aGHLZKfwHkcxLZuh8ex6jFo0fNg"
    };
    bodys=JSON.stringify(bodys);
    let result=await new Promise((resolve, reject)=>{
        requset({
            uri:'https://a1.easemob.com/1115181113019206/ceshi/token',
            method:'POST',
            headers:{
                "Accept":"application/json",
                "Content-Type":"application/json"
            },
            body:bodys
        },(error, response, body)=>{
            if(error!==null){
                resolve({Code:'0',msg:error})
            }else {
                resolve({Code:'1',data:body})
            }
        })
    });
    ctx.body=result
});



module.exports=router;


